home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2003 May / PFA0503.iso / fullversioner / webmenubuilder / WebMenuBuilder2demo / setup.exe / {app} / help / ProgressBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-03-22  |  3.4 KB  |  171 lines

  1. import java.awt.Canvas;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6.  
  7. public class ProgressBar extends Canvas {
  8.    private boolean progressBarVisible;
  9.    private boolean percentMessageVisible;
  10.    private Color completedPartColor;
  11.    private Color remainingPartColor;
  12.    private Color textColor;
  13.    private String message;
  14.    private int maximumValue;
  15.    private int currentValue;
  16.  
  17.    public ProgressBar(int var1, Color var2, Color var3, Color var4, String var5) {
  18.       if (var2 == null) {
  19.          throw new IllegalArgumentException("null completedPartColor");
  20.       } else {
  21.          this.completedPartColor = var2;
  22.          if (var3 == null) {
  23.             throw new IllegalArgumentException("null remainingPartColor");
  24.          } else {
  25.             this.remainingPartColor = var3;
  26.             if (var4 == null) {
  27.                throw new IllegalArgumentException("null textColor");
  28.             } else {
  29.                this.textColor = var4;
  30.                if (var1 <= 0) {
  31.                   throw new IllegalArgumentException("maximumValue < 0");
  32.                } else {
  33.                   this.maximumValue = var1;
  34.                   if (var5 == null) {
  35.                      throw new IllegalArgumentException("null message");
  36.                   } else {
  37.                      this.message = var5;
  38.                      this.progressBarVisible = true;
  39.                      this.percentMessageVisible = true;
  40.                   }
  41.                }
  42.             }
  43.          }
  44.       }
  45.    }
  46.  
  47.    public Color getCompletedPartColor() {
  48.       return this.completedPartColor;
  49.    }
  50.  
  51.    public void setCompletedPartColor(Color var1) {
  52.       this.completedPartColor = var1;
  53.       ((Component)this).repaint();
  54.    }
  55.  
  56.    public Color getRemainingPartColor() {
  57.       return this.remainingPartColor;
  58.    }
  59.  
  60.    public void setRemainingPartColor(Color var1) {
  61.       this.remainingPartColor = var1;
  62.       ((Component)this).repaint();
  63.    }
  64.  
  65.    public Color getTextColor() {
  66.       return this.textColor;
  67.    }
  68.  
  69.    public void setTextColor(Color var1) {
  70.       this.textColor = var1;
  71.       ((Component)this).repaint();
  72.    }
  73.  
  74.    public boolean isPercentMessageVisible() {
  75.       return this.percentMessageVisible;
  76.    }
  77.  
  78.    public void setPercentMessageVisible(boolean var1) {
  79.       this.percentMessageVisible = var1;
  80.       ((Component)this).repaint();
  81.    }
  82.  
  83.    public String getMessage() {
  84.       return this.message;
  85.    }
  86.  
  87.    public void setMessage(String var1) {
  88.       this.message = var1;
  89.       ((Component)this).repaint();
  90.    }
  91.  
  92.    public void setMaximumValue(int var1) {
  93.       this.maximumValue = var1;
  94.       ((Component)this).repaint();
  95.    }
  96.  
  97.    public int getMaximumValue() {
  98.       return this.maximumValue;
  99.    }
  100.  
  101.    public int getCurrentValue() {
  102.       return this.currentValue;
  103.    }
  104.  
  105.    public void setCurrentValue(int var1) {
  106.       this.currentValue = var1;
  107.       ((Component)this).repaint();
  108.    }
  109.  
  110.    public double getPercentDone() {
  111.       return (double)100.0F * (double)this.currentValue / (double)this.maximumValue;
  112.    }
  113.  
  114.    public int changeBy(int var1) {
  115.       int var2 = this.currentValue + var1;
  116.       if (var2 > this.maximumValue) {
  117.          var2 = this.maximumValue;
  118.       } else if (var2 < 0) {
  119.          var2 = 0;
  120.       }
  121.  
  122.       this.currentValue = var2;
  123.       ((Component)this).repaint();
  124.       return this.currentValue;
  125.    }
  126.  
  127.    public void reset() {
  128.       this.currentValue = 0;
  129.       ((Component)this).repaint();
  130.    }
  131.  
  132.    public void paint(Graphics var1) {
  133.       Dimension var2 = ((Component)this).size();
  134.       int var3 = var2.width;
  135.       int var4 = var2.height;
  136.       if (this.progressBarVisible) {
  137.          var1.setColor(this.remainingPartColor);
  138.          var1.fillRect(0, 0, var3, var4);
  139.          if (this.currentValue > 0) {
  140.             float var5 = (float)this.currentValue / (float)this.maximumValue;
  141.             if (var5 > 1.0F) {
  142.                var5 = 1.0F;
  143.             }
  144.  
  145.             int var6 = (int)((float)(var3 - 2) * var5);
  146.             var1.setColor(this.completedPartColor);
  147.             var1.fillRect(1, 1, var6, var4 - 2);
  148.             int var7 = (int)((double)100.0F * (double)var5);
  149.             if (this.percentMessageVisible) {
  150.                var1.setColor(this.textColor);
  151.                var1.drawString(this.message + " " + var7 + "%", 4, var4 - 5);
  152.                return;
  153.             }
  154.          }
  155.       } else {
  156.          var1.setColor(((Component)this).getParent().getBackground());
  157.          var1.fillRect(0, 0, var3, var4);
  158.       }
  159.  
  160.    }
  161.  
  162.    public void setProgressBarVisible(boolean var1) {
  163.       this.progressBarVisible = var1;
  164.       ((Component)this).repaint();
  165.    }
  166.  
  167.    public boolean isProgressBarVisible() {
  168.       return this.progressBarVisible;
  169.    }
  170. }
  171.